package com.itheima.exception;

import com.itheima.entity.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/15 17:08
 * @description： 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionInvoker {

    @ExceptionHandler
    public Result handlerException(Exception ex){
        ex.printStackTrace();
        String msg = null;
        if (ex.getMessage().length()>200){
            msg = ex.getMessage().substring(0,200);
        }else {
            msg = ex.getMessage();
        }
        return new Result(false, msg);
    }
}
